package cn.tedu.recruitmentwebsite.employee.service.impl;

import cn.tedu.recruitmentwebsite.employee.pojo.dto.QueryParam;
import cn.tedu.recruitmentwebsite.employee.pojo.dto.SavePositionParam;
import cn.tedu.recruitmentwebsite.base.pojo.entity.Job;
import cn.tedu.recruitmentwebsite.base.pojo.vo.JobVO;
import cn.tedu.recruitmentwebsite.employee.mapper.EmployeeMapper;
import cn.tedu.recruitmentwebsite.employee.service.PositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class PositionServiceImpl implements PositionService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<JobVO> getAllPosition(QueryParam queryParam) {
        List<JobVO> jobs = employeeMapper.getAllPosition(queryParam);
        log.debug("查询所有职位：{}",jobs);
        return jobs;
    }

    @Override
    public void savePosition(SavePositionParam savePositionParam) {
        Job job = new Job();
        BeanUtils.copyProperties(savePositionParam,job);
        job.setCreateTime(new Date());
        job.setStatus("1");
        if (job.getId()==null){
            log.debug("新增岗位-插入表中的数据:job={}",job);
            employeeMapper.savePosition(job);
        }else {
            job.setUpdateTime(new Date());
            log.debug("修改岗位-修改表中的数据:job={}",job);
            employeeMapper.updatePosition(job);
        }
    }

    @Override
    public JobVO getPositionById(Long id) {
        return employeeMapper.getPositionById(id);
    }

    @Override
    public void deletePosition(Long id) {
        employeeMapper.deletePositionById(id);
    }

    @Override
    public void updatePosition(Long id) {
        Map map = new HashMap();
        map.put("id",id);
        map.put("status","0");
        employeeMapper.updatePositionStatus(map);
    }
}
